package com.song.study.springcloudconsumer.controller;

import com.song.study.springcloudconsumer.OrderInfo;
import com.song.study.springcloudconsumer.service.OrderApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@RequestMapping(value = "/client")
public class TestController {

    private final RestTemplate restTemplate;

    @Autowired
    private OrderApi orderApi;


    @Autowired
    public TestController(RestTemplate restTemplate){
        this.restTemplate = restTemplate;
    }

    @GetMapping(value = "/test/{params}")
    public Object getTest(@PathVariable("params") String params){
        String forObject = restTemplate.getForObject("http://springcloud-service/order/get/" + params, String.class);
        return "result: " + forObject;
    }

    @GetMapping(value = "/test2/{params}")
    public Object getOrderInfo(@PathVariable("params") String params){
        OrderInfo orderInfo = orderApi.getOrderInfo(params);
        return "result: " + orderInfo;
    }
}
